/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package codegener.comp;

import codegener.entity.ColumnInfo;
import codegener.entity.DsBean;
import codegener.entity.GenerBean;
import codegener.entity.TableInfo;
import codegener.entity.Tabs;
import codegener.tool.DBGet;
import codegener.tool.Gener;
import codegener.util.JsonUtils;
import codegener.util.StrUtils;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.swing.DefaultListModel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author 32181
 */
public class MFrame extends javax.swing.JFrame implements ActionListener{

    private SetupDialog setupDialog;
    private DefaultListModel listModel=new DefaultListModel();
    private JPopupMenu tabListPopupMenu;
    private JPopupMenu checkTabPopupMenu;
    
    private DefaultTableModel tabModel;//显示表字段信息
    private DefaultTableModel datModel;//显示表数据信息
    private DefaultTableModel peProjectModel;//对比数据表字段是否存在
    
    
    private static DsJDialog dsJDialog=null;
    /**
     * Creates new form MFrame
     */
    public MFrame() {
        init();
        initComponents();
        setTitle("Java开发工具");
        setupDialog=new SetupDialog(this,true);
        tabList.setModel(listModel);
        tabListPopupMenu=new JPopupMenu();
        JMenu menus=new JMenu("选择生成");
        JMenuItem beanItem=new JMenuItem("生成Bean");
        beanItem.setActionCommand("bean");
        beanItem.addActionListener(this);
        menus.add(beanItem);
        
        JMenuItem serviceItem=new JMenuItem("生成Service");
        serviceItem.setActionCommand("service");
        serviceItem.addActionListener(this);
        menus.add(serviceItem);
        
        JMenuItem actionItem=new JMenuItem("生成Controller");
        actionItem.setActionCommand("action");
        actionItem.addActionListener(this);
        menus.add(actionItem);
        
        JMenuItem mapperItem=new JMenuItem("生成Mapper");
        mapperItem.setActionCommand("mapper");
        mapperItem.addActionListener(this);
        menus.add(mapperItem);
        
        JMenuItem mapperXMLItem=new JMenuItem("生成MapperXML");
        mapperXMLItem.setActionCommand("mapperXML");
        mapperXMLItem.addActionListener(this);
        menus.add(mapperXMLItem);
        
        JMenuItem allItem=new JMenuItem("生成所有");
        allItem.setActionCommand("all");
        allItem.addActionListener(this);
        menus.add(allItem);
        
        tabListPopupMenu.add(menus);
        
        menus=new JMenu("同步数据");
        
        JMenuItem syncItem=new JMenuItem("同步到");
        syncItem.setActionCommand("syncData");
        syncItem.addActionListener(this);
        menus.add(syncItem);
        tabListPopupMenu.add(menus);
        
        
        checkTabPopupMenu=new JPopupMenu();
        JMenu menusCheck=new JMenu("检查表结构");
        List<TableInfo> checkTabs=Tabs.getCheckTable();
        if(null!=checkTabs&&!checkTabs.isEmpty()){
            for(TableInfo checkTab:checkTabs){
                JMenuItem temp=new JMenuItem("检测"+checkTab.getName());
                temp.setActionCommand("checkTab#"+checkTab.getName());
                temp.addActionListener(this);
                menusCheck.add(temp);
            }
        }
        checkTabPopupMenu.add(menusCheck);
        flush();
        
        dsJDialog=new DsJDialog(this,true);
        initMenu();
        
    }
    
    private JMenu dsItem=null;
    private void initMenu(){
        JMenuItem addds=new JMenuItem("新增数据源");
        addds.setActionCommand("addds");
        addds.addActionListener(this);
        fileMenu.add(addds);
        
        JMenuItem editds=new JMenuItem("编辑数据源");
        editds.setActionCommand("editds");
        editds.addActionListener(this);
        fileMenu.add(editds);
        
        dsItem=new JMenu("切换数据源");
        List<DsBean> dss=dsJDialog.getDss();
        if(null!=dss&&!dss.isEmpty()){
            for(DsBean ds:dss){
                JMenuItem meun=new JMenuItem(ds.getTitle());
                meun.setActionCommand("tods_"+ds.getTitle());
                meun.addActionListener(this);
                dsItem.add(meun);
            }
        }
        fileMenu.add(dsItem);
    }
    
    public void addDsMenu(String title){
        JMenuItem meun=new JMenuItem(title);
        meun.setActionCommand("tods_"+title);
        meun.addActionListener(this);
        dsItem.add(meun);
    }
    
    private void init(){
        tabModel=new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "字段名称", "字段类型", "字段默认值", "字段备注", "是否为主键"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        };
        
        datModel=new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "表名称", "记录行数"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        };
        
        
        
        peProjectModel=new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "标准字段名称", "标准字段类型","检测结果"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false,false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        };
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        toolBar = new javax.swing.JToolBar();
        setupBtn = new javax.swing.JButton();
        tableBtn = new javax.swing.JButton();
        tempBtn = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        checkTabBtn = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        refreshBtn = new javax.swing.JButton();
        queryText = new javax.swing.JTextField();
        queryBtn = new javax.swing.JButton();
        jsp = new javax.swing.JSplitPane();
        leftScrollPane = new javax.swing.JScrollPane();
        tabList = new javax.swing.JList<>();
        rightScrollPane = new javax.swing.JScrollPane();
        tabTable = new javax.swing.JTable();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        editMenu = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(860, 520));

        toolBar.setRollover(true);

        setupBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/codegener/setup.png"))); // NOI18N
        setupBtn.setToolTipText("设置");
        setupBtn.setFocusable(false);
        setupBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        setupBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        setupBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setupBtnActionPerformed(evt);
            }
        });
        toolBar.add(setupBtn);

        tableBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/codegener/tjtable.png"))); // NOI18N
        tableBtn.setToolTipText("数据量统计");
        tableBtn.setFocusable(false);
        tableBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tableBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tableBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tableBtnActionPerformed(evt);
            }
        });
        toolBar.add(tableBtn);

        tempBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/codegener/table.png"))); // NOI18N
        tempBtn.setToolTipText("表字段信息");
        tempBtn.setFocusable(false);
        tempBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tempBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tempBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tempBtnActionPerformed(evt);
            }
        });
        toolBar.add(tempBtn);
        toolBar.add(jSeparator1);

        checkTabBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/codegener/check.png"))); // NOI18N
        checkTabBtn.setToolTipText("检查表结构");
        checkTabBtn.setFocusable(false);
        checkTabBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        checkTabBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        checkTabBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                checkTabBtnMouseClicked(evt);
            }
        });
        checkTabBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkTabBtnActionPerformed(evt);
            }
        });
        toolBar.add(checkTabBtn);
        toolBar.add(jSeparator2);

        refreshBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/codegener/refresh.png"))); // NOI18N
        refreshBtn.setToolTipText("刷新");
        refreshBtn.setFocusable(false);
        refreshBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        refreshBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        refreshBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshBtnActionPerformed(evt);
            }
        });
        toolBar.add(refreshBtn);

        queryText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                queryTextKeyTyped(evt);
            }
        });
        toolBar.add(queryText);

        queryBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/codegener/query.png"))); // NOI18N
        queryBtn.setToolTipText("查询");
        queryBtn.setFocusable(false);
        queryBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        queryBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        queryBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                queryBtnActionPerformed(evt);
            }
        });
        toolBar.add(queryBtn);

        jsp.setDividerLocation(200);

        tabList.setMaximumSize(new java.awt.Dimension(250, 85));
        tabList.setMinimumSize(new java.awt.Dimension(250, 85));
        tabList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabListMouseClicked(evt);
            }
        });
        leftScrollPane.setViewportView(tabList);

        jsp.setLeftComponent(leftScrollPane);

        tabTable.setModel(tabModel);
        rightScrollPane.setViewportView(tabTable);

        jsp.setRightComponent(rightScrollPane);

        fileMenu.setText("文件");
        menuBar.add(fileMenu);

        editMenu.setText("编辑");
        menuBar.add(editMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBar, javax.swing.GroupLayout.DEFAULT_SIZE, 860, Short.MAX_VALUE)
            .addComponent(jsp)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jsp, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void setupBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setupBtnActionPerformed
        // TODO add your handling code here:
        setupDialog.setLocationRelativeTo(null);
        setupDialog.setVisible(true);
    }//GEN-LAST:event_setupBtnActionPerformed

    private void refreshBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshBtnActionPerformed
        // TODO add your handling code here:
        flush();
    }//GEN-LAST:event_refreshBtnActionPerformed

    private void queryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_queryBtnActionPerformed
        // TODO add your handling code here:
        listModel.clear();
        tables=DBGet.listTables(queryText.getText());
        if(null!=tables&&!tables.isEmpty()){
             for(String table:tables){
                 listModel.addElement(table);    
             }
        }
    }//GEN-LAST:event_queryBtnActionPerformed

    private void queryTextKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_queryTextKeyTyped
        // TODO add your handling code here:
        if(null!=tables&&!tables.isEmpty()){
            listModel.clear();
            List<String> subTables=tables.stream().filter((t) -> {
                if(t.contains(queryText.getText())||t.contains(queryText.getText().toUpperCase())||t.contains(queryText.getText().toLowerCase())){
                    return true;
                }
                return false; //To change body of generated lambdas, choose Tools | Templates.
            }).collect(Collectors.toList());
            if(null!=subTables&&!subTables.isEmpty()){
                for(String table:subTables){
                 listModel.addElement(table);    
                }
            }
            
        }
    }//GEN-LAST:event_queryTextKeyTyped

    private void tabListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabListMouseClicked
        // TODO add your handling code here:
        DefaultTableModel model=(DefaultTableModel)tabTable.getModel();
        model.setRowCount(0);
        String tableName=tabList.getSelectedValue();
        if(StrUtils.isNotBlank(tableName)){
            tableInfo=DBGet.getTable(tableName).get(0);
            if("table".equals(MFrame.showType)){
                if(null!=tableInfo.getColumns()&&!tableInfo.getColumns().isEmpty()){
                    for(ColumnInfo info:tableInfo.getColumns()){
                        model.addRow(new Object[]{info.getCname(),info.getDataType(),"null",info.getComments(),info.isPrimary()});        
                    }
                    tabTable.setToolTipText(tableInfo.getTabcomment());
                }
            }else if("tableDat".equals(MFrame.showType)){
                List<TableInfo> tableInfos=DBGet.getTableDat(tableName);
                if(null!=tableInfos&&!tableInfos.isEmpty()){
                    TableInfo info=tableInfos.get(0);
                    datModel.addRow(new Object[]{info.getName(),info.getNumRows()});        
                }
            }

            if(evt.getButton() == 3){
                tabListPopupMenu.show(tabList,evt.getX(), evt.getY());
            }
        }
       
        
    }//GEN-LAST:event_tabListMouseClicked

    private void tempBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tempBtnActionPerformed
        // TODO add your handling code here:
        MFrame.showType="table";
        tabTable.setModel(tabModel);
    }//GEN-LAST:event_tempBtnActionPerformed

    /**
     * table 表字段信息
     * tableDat 表数据量统计
     */
    public static String showType="table";
    private void tableBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tableBtnActionPerformed
        // TODO add your handling code here:
        
        tabTable.setModel(datModel);
        datModel.setRowCount(0);
        
        List<TableInfo> tableInfos=DBGet.getTableDat(null);
            if(null!=tableInfos&&!tableInfos.isEmpty()){
                for(TableInfo info:tableInfos){
                    datModel.addRow(new Object[]{info.getName(),info.getNumRows()});        
                }
            }
        MFrame.showType="tableDat";
         //rightScrollPane.setViewportView(new JTextArea());
    }//GEN-LAST:event_tableBtnActionPerformed

    private void checkTabBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkTabBtnActionPerformed
        // TODO add your handling code here:
        MFrame.showType="check";
        tabTable.setModel(peProjectModel);
    }//GEN-LAST:event_checkTabBtnActionPerformed

    private void checkTabBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkTabBtnMouseClicked
        // TODO add your handling code here:
        checkTabPopupMenu.show(checkTabBtn,evt.getX(), evt.getY());
    }//GEN-LAST:event_checkTabBtnMouseClicked

    private void checkTab(TableInfo tab){
         
        List<TableInfo> tabInfos=DBGet.getTable(tab.getName());
        if(null!=tabInfos&&!tabInfos.isEmpty()){
            TableInfo tabInfo=tabInfos.get(0);
            List<ColumnInfo> csList=tabInfo.getColumns();
            
            if(null==csList||csList.isEmpty()){
                JOptionPane.showMessageDialog(this, tab.getName()+"表不存在");
                return ;
            }
            peProjectModel.setRowCount(0);
            TableInfo peProject=tab;
            for(ColumnInfo ci:peProject.getColumns()){
                String r="不存在";
                boolean name=false;
                boolean type=false;
                for(ColumnInfo c:csList){
                    if(ci.getCname().equals(c.getCname())){
                        name=true;
                        if(ci.getDataType().equals(c.getDataType())){
                            type=true;
                        }
                    }
                }
                
                if(name){
                    r="类型不一致";
                    if(type){
                        r="完全一致";
                    }
                }
                peProjectModel.addRow(new Object[]{ci.getCname(),ci.getDataType(),r});
            }
        }else{
            JOptionPane.showMessageDialog(this, tab.getName()+"表不存在");
        }
    }
    
    private List<Map<String,Object>> readyGenerData(String basePkg){
        List<Map<String,Object>> datas=new ArrayList<>();
        GenerBean gb=setupDialog.getGenerBean();
        String saveDir=gb.getDir()==null?"./":gb.getDir();
        
                                
        List<String> tableNames=tabList.getSelectedValuesList();
        if(null!=tableNames&&!tableNames.isEmpty()){
            List<TableInfo> tabInfos=DBGet.getTable(tableNames.toArray(new String[]{}));
            //System.err.println("tabInfos="+JsonUtils.toJsonStr(tabInfos));
            for(TableInfo tab:tabInfos){
                Map<String,Object> data=new HashMap<>();
                data.put("basePkg", basePkg);
                data.put("path", "sys");
	        data.put("pathDir", "system");
                
                String tabFixName=tab.getName();
                if(null!=gb.getTabQian()&&gb.getTabQian().trim().length()>0){
                    String[] qians=gb.getTabQian().trim().split(",");
                    for(String qian:qians){
                        if(tabFixName.startsWith(qian)){
                            tabFixName=tabFixName.replaceFirst(qian, "");
                        }
                    }
                }
                
                if(null!=gb.getTabHou()&&gb.getTabHou().trim().length()>0){
                    String[] qians=gb.getTabHou().trim().split(",");
                    for(String qian:qians){
                        if(tabFixName.endsWith(qian)){
                            tabFixName=tabFixName.substring(0, tabFixName.indexOf(qian));
                        }
                    }
                }
                
                String BeanName=StrUtils.headUpper(StrUtils.dropUnderline(tab.getName()));
                String beanName=StrUtils.dropUnderline(tab.getName());
                data.put("beanFileName", saveDir+String.format("/"+basePkg.replaceAll("\\.", "/")+"/"+gb.getBeanSuffix()+"/%s.java",BeanName));
                data.put("mapperFileName", saveDir+String.format("/"+basePkg.replaceAll("\\.", "/")+"/"+gb.getMapperSuffix()+"/%sMapper.java",BeanName));
		data.put("xmlmapperFileName", saveDir+String.format("/"+basePkg.replaceAll("\\.", "/")+"/"+gb.getMapperSuffix()+"/%sMapper.xml",BeanName));
		data.put("serviceFileName", saveDir+String.format("/"+basePkg.replaceAll("\\.", "/")+"/"+gb.getServiceSuffix()+"/%sService.java",BeanName));
		data.put("actionFileName", saveDir+String.format("/"+basePkg.replaceAll("\\.", "/")+"/"+gb.getControllerSuffix()+"/%sAction.java",BeanName));
                data.put("tableName", tab.getName());
                data.put("beanName", beanName);
                data.put("BeanName", BeanName);
                data.put("tabComment", tab.getTabcomment());
                data.put("fields", tab.getColumns());
                
                List<ColumnInfo> cos=tab.getColumns();
			if(null!=cos&&!cos.isEmpty()){
				for(ColumnInfo ci:cos){
					if(null!=ci&&ci.isPrimary()){
						data.put("priKey", StrUtils.dropUnderline(ci.getName()));
						data.put("priKeyType", ci.getJavaType());
						data.put("priKeyColumn", ci.getCname());
					}
				}
			}
                if(null==data.get("priKey")){
                    data.put("priKey", "id");
                }
                if(null==data.get("priKeyType")){
                    data.put("priKeyType", "String");
                }
                if(null==data.get("priKeyColumn")){
                    data.put("priKeyColumn", "id");
                }
                datas.add(data);
            }
        }
        return datas;
    }
    
    
    public void flush(){
        setupDialog.initDsAndTemp();
        DefaultTableModel model=(DefaultTableModel)tabTable.getModel();
        model.setRowCount(0);
        listModel.clear();
        tables=DBGet.listTables();
        if(null!=tables&&!tables.isEmpty()){
             
             for(String table:tables){
                 listModel.addElement(table);    
             }
             
             
            tableInfo=DBGet.getTable(tables.get(0)).get(0);
            if(null!=tableInfo.getColumns()&&!tableInfo.getColumns().isEmpty()){
                for(ColumnInfo info:tableInfo.getColumns()){
                    model.addRow(new Object[]{info.getCname(),info.getDataType(),"null",info.getComments(),info.isPrimary()});        
                }
            }
            
         }
    }
  
    private TableInfo tableInfo=null;
    private List<String> tables=null;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton checkTabBtn;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JSplitPane jsp;
    private javax.swing.JScrollPane leftScrollPane;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JButton queryBtn;
    private javax.swing.JTextField queryText;
    private javax.swing.JButton refreshBtn;
    private javax.swing.JScrollPane rightScrollPane;
    private javax.swing.JButton setupBtn;
    private javax.swing.JList<String> tabList;
    private javax.swing.JTable tabTable;
    private javax.swing.JButton tableBtn;
    private javax.swing.JButton tempBtn;
    private javax.swing.JToolBar toolBar;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent ae) {
        String cmd=ae.getActionCommand();
        if(cmd.startsWith("checkTab")){
                        
            String tableNameString=cmd.split("#")[1];
           
            TableInfo tab=Tabs.getCheckTable(tableNameString);
            if(null!=tab){
                checkTab(tab);
            }
            return ;
        }
        
        if(cmd.startsWith("tods_")){
            
            DsBean dsBean=dsJDialog.getDsBean(cmd.split("_")[1]);
            if(null!=dsBean){
                dsJDialog.setVisible(false);
                dsBean.setSelected(true);
                DBGet.initDs(dsBean.getType(), dsBean.getUrl(), dsBean.getUname(), dsBean.getUpass());
                dsJDialog.seletcedDsBean(dsBean);
                flush();
            }
            return;
        }
        
        
        switch(cmd){
            case "bean":{
                String basePkg = JOptionPane.showInputDialog("请输入基础包路径：");
                List<Map<String,Object>> datas=readyGenerData(basePkg);
                if(null!=datas&&!datas.isEmpty()){
                    for(Map<String,Object> data:datas){
                        Gener.generBean(data);
                    }
                }
                
            }break;
            case "service":{
                String basePkg = JOptionPane.showInputDialog("请输入基础包路径：");
                List<Map<String,Object>> datas=readyGenerData(basePkg);
                if(null!=datas&&!datas.isEmpty()){
                    for(Map<String,Object> data:datas){
                         Gener.generService(data);
                    }
                }
               
            }break;
            case "mapper":{
                String basePkg = JOptionPane.showInputDialog("请输入基础包路径：");
                List<Map<String,Object>> datas=readyGenerData(basePkg);
                if(null!=datas&&!datas.isEmpty()){
                    for(Map<String,Object> data:datas){
                        Gener.generMapper(data);
                    }
                }
                
            }break;
            case "mapperXML":{
                String basePkg = JOptionPane.showInputDialog("请输入基础包路径：");
                List<Map<String,Object>> datas=readyGenerData(basePkg);
                if(null!=datas&&!datas.isEmpty()){
                    for(Map<String,Object> data:datas){
                        Gener.generXMLMapper(data);
                    }
                }
                
            }break;
            case "action":{
                String basePkg = JOptionPane.showInputDialog("请输入基础包路径：");
                List<Map<String,Object>> datas=readyGenerData(basePkg);
                if(null!=datas&&!datas.isEmpty()){
                    for(Map<String,Object> data:datas){
                        Gener.generAction(data);
                    }
                }
                
            }break;
            case "all":{
                String basePkg = JOptionPane.showInputDialog("请输入基础包路径：");
                List<Map<String,Object>> datas=readyGenerData(basePkg);
                if(null!=datas&&!datas.isEmpty()){
                    for(Map<String,Object> data:datas){
                         Gener.generBean(data);
                        Gener.generService(data);
                        Gener.generMapper(data);
                        Gener.generXMLMapper(data);
                        Gener.generAction(data);
                    }
                }
               
            }break;
            case "addds":{
                dsJDialog.setVisible(true);
            }break;
            case "editds":{
                dsJDialog.showEditDialog();
            }
            
        }
    }
}
